//不给初始值
class Foo {
    showAge(arg0: number) {
        throw new Error("Method not implemented.");
    }
    //不给初始值
    username!:string;
}

let f:Foo = new Foo();
f.username = '123';

//类
class Foo1 {
    username:string;
    age:number;
    constructor(username:string , age:number){
        this.username = username
        this.age = age
    }

    showAge = (n:number) => {
        return n;
    }
}

let f1 = new Foo1('123',123);
f1.showAge(123);

class Foo2 {
    username;

    constructor() {
        this.username = '123'
    }
}

//接口与类
interface A{
    username:string
    age?:number
    showName(n:string):string
}

class Foo3 implements A{
    username:string = '1'
    age?:number = 1
    showName = (n:string):string => {
        return n;
    }
}

let f3 = new Foo3();
f3.showName('123')

//泛型与类

class Foo4<T> {
    username:T
    constructor(username:T) {
        this.username = username
    }
}

class Bar extends Foo4<string>{

}

let bar = new Bar('123')

//泛型与接口
interface Z<T>{
    username:T
    age:number
    showName(n:T):T
}

class Z1 implements Z<string>{
    age!: number;
    username:string = '123'
    showName(n: string): string {
        return n;
    }
}

let z = new Z1();
z.showName('123')
z.age = 123